package com.example.sekerim;

import java.io.IOException;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class FoodSelectionFragment extends Fragment {

	private TextView mTextViewCalorieText;
	private TextView mTextViewCalorieAmount;
	private Patient patient = new Patient();
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {             
	    View rootView = inflater.inflate(R.layout.fragment_food_selection, container, false);
		try {
			patient = (Patient) InternalStorage.readObject(getActivity(), Constants.shared_info);
		} catch (ClassNotFoundException e) {
			   Log.e("While reading", e.getMessage());
		} catch (IOException e) {
			   Log.e("While reading", e.getMessage());
		}
	    
		mTextViewCalorieText = (TextView) rootView.findViewById(R.id.food_selection_calorie_text);
		mTextViewCalorieText.setText(Constants.food_selection_calorie_text);

		mTextViewCalorieAmount = (TextView) rootView.findViewById(R.id.food_selection_calorie_amount);
		mTextViewCalorieAmount.setText(calculateCalorieNeed());
		
		String s = SaveSharedPreference.getMailAddress(getActivity()) + "-" +
				patient.getPassword() + "-" +
				patient.getUserName() + "-" +
				patient.getUserSurname() + "-" +
				"isMale:" + patient.isMale() + "-" +
				patient.getBirthdayDay() + "/" + patient.getBirthdayMonth() + "/" + patient.getBirthdayYear()
				+ patient.getEthnicity();
		
	    return rootView;
	}
	
	public String calculateCalorieNeed()
	{
		int average = 2000;
		int age = patient.getAge();
		
		if(age<25)
			average += 250;
		if(age>40)
			average -= 250;
		
		if(!patient.isMale())
			average -= 150;
		
		if(patient.getHeight()<170)
			average -= 150;
		if(patient.getHeight()>180)
			average += 75;
		
		return String.valueOf(average);
	}
	
}
